package com.novel.download.utils;

import org.springframework.util.StringUtils;

import java.io.*;
import java.util.regex.Pattern;

public class ReadUtil {

    private static final String category = "11";
//    private static final Pattern pattern = Pattern.compile("[0-9]{3}、.*");
    private static final Pattern pattern = Pattern.compile("^.?第(.{1,5})[章部集卷节篇回].{0,24}");

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "UTF-8"));
        String line;
        int count = 0;
        boolean flag = true;
        while ((line = reader.readLine()) != null) {
            if (flag && StringUtils.hasLength(category) && !line.contains(category)) {
                continue;
            } else {
                flag = false;
            }
            print(line);
            if (pattern.matcher(line).find()) {
                count++;
            }
            if (count > 20) {
                break;
            }
        }
    }

    private static void print(String line) {
        while (line.length() > 100) {
            System.out.println(line.substring(0, 100));
            line = line.substring(100);
        }
        System.out.println(line);
    }

    private static final String filePath = "D:\\study\\novelDownloadPath\\";
}
